<?php

namespace KGK\StoreBundle\Controller;

use Symfony\Component\DependencyInjection\ContainerAware,
       Symfony\Component\HttpFoundation\RedirectResponse;
use KGK\StoreBundle\Entity\Categorie;

class DefaultController extends ContainerAware 
{
	public function indexAction($cat = null)
	{
		$em = $this->container->get('doctrine')->getEntityManager();
		
		if (isset($cat))
		{
			$query = $em->createQuery('SELECT p FROM KGK\StoreBundle\Entity\Produit p WHERE p.cat = ?1');
			$query->setParameter(1, $cat);
			$produit = $query->getResult();
		}
		else
		{
			$produit = $em->getRepository('KGKStoreBundle:Produit')->findAll();
		}
		
		return $this->container->get('templating')->renderResponse(
		'KGKStoreBundle:Default:index.html.twig', array('produit' => $produit));
	}
}